package lanou.giftsay_01.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import lanou.giftsay_01.bean.ScrollBean;
import lanou.giftsay_01.R;

/**
 * Created by dllo on 16/8/16.
 */
public class MyRvAdapter extends RecyclerView.Adapter<MyRvAdapter.MyViewHolder> {
    private ArrayList<ScrollBean> arrayList ;
    private Context context ;

    public MyRvAdapter(Context context) {
        this.context = context;
    }

    public void setArrayList(ArrayList<ScrollBean> arrayList) {
        this.arrayList = arrayList;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_rv , parent , false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Picasso.with(context).load(arrayList.get(0).getData().getSecondary_banners().get(position).getImage_url()).into(holder.iv);
    }

    @Override
    public int getItemCount() {
        return  arrayList != null ? arrayList.get(0).getData().getSecondary_banners().size() : 0;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv;
        public MyViewHolder(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.rv_iv);
        }
    }



}
